﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetworkSimulator
{
    class DORA : Routing
    {
        private int bwp;

        public int BWP
        {
            set { this.bwp = value; }
        }

        public DORA()
            : base()
        {
            this.bwp = 1;
        }

        private int[,] ppv;

        public override Path getPath(Request req)
        {
            this.Renew();

            // If had at least one path from source to destination
            if (BFS(nodes[req.Source], nodes[req.Destination]).Links.Count > 0)
            {
                // Generate link weight
                GenerateDORACost();

                // Remove links with less bandwidth than request bandwidth
                this.removeLinks(req.Bandwidth);

                // Use Dijkstra to get path
                return dijkstra(nodes[req.Source], nodes[req.Destination]);
            }
            return new Path();
        }

        private void GenerateDORACost()
        {
            ppv = offline_DORA.PPV;

            List<Link> linkList = map.Links;
            double max = (from l in linkList select l.Capacity).Max();
            double min = (from l in linkList select l.Capacity).Min();
            double delta = max - min;

            
            int _max = ppv.Cast<int>().Max();
            int _min = ppv.Cast<int>().Min();

            int i = 0;
            int j = 0;
            foreach (var l in linkList)
            {
                foreach (IngressEgress ie in  ieList.IngressEgressList)
                {
                    cost[l] = ((1 - bwp) * min * (max - l.Capacity) * _max) / (l.Capacity * delta) + (1 - bwp) * _min;
                    j++;
                }
                j = 0;
                i++;
            }           
        }
    }
}
